package games.platformer.actions;

import vooga.entities.Entity;
import java.util.Collection;

/**
 * An action for climbing up or down a ladder when you are on top of it
 * 
 * @author bshelton
 * @author Jonathan Odom
 *
 */

public class ClimbLadderAction implements vooga.actions.Action {

	boolean climbedFlag;
	boolean active;
	Entity myPlayerCharacter;
	Collection<Entity> myLadderEntities;
	double myClimbSpeed;
	
	public ClimbLadderAction(Entity playerCharacter, Collection<Entity> ladderEntities, double climbSpeed) {
		myPlayerCharacter = playerCharacter;
		myLadderEntities = ladderEntities;
		myClimbSpeed = climbSpeed;
		active = false;
		climbedFlag = false;
	}
	
	public void start()
	{
		if(!active)
		{
			fire();
			active = true;
		}
		
	}
	
	public void stop()
	{
		if(climbedFlag == true)
		{
			myPlayerCharacter.getVelocity().setYChange(0);
		}
		
		active = false;
	}
	
	public void fire()
	{
		for(Entity e: myLadderEntities)
		{
			if(myPlayerCharacter.intersects(e))
			{
				myPlayerCharacter.getVelocity().setYChange(-1 * myClimbSpeed);
				climbedFlag = true;
			}
		}
	}
	

}
